<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%String path = request.getContextPath(); %>
<!DOCTYPE html>
<html>
<head>
<base href="<%=path%>/">
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="layui/layui/css/layui.css" media="all" />
</head>
<body class="childrenBody">
	<form class="layui-form">
	<input type="hidden" name="id" value="${user.id }"/>
		<div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input newsName" lay-verify="required" placeholder="请输入用户名" name="userName" value="${user.userName }">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">密码</label>
			<div class="layui-input-block">
				<input type="password" class="layui-input newsName" lay-verify="required" placeholder="请输入密码" name="pwd" value="${user.pwd }">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">姓名</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input newsName" lay-verify="required" placeholder="请输入姓名" name="realName" value="${user.realName }">
			
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">性别</label>
			<div class="layui-input-block">
			   <input type="radio" name="sex" value="0" title="男" <c:if test="${user.sex==0 }">checked</c:if>>
      			<input type="radio" name="sex" value="1" title="女"  <c:if test="${user.sex==1 }">checked</c:if>>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">状态</label>
			<div class="layui-input-block">
			<input type="hidden" name="flag" <c:if test="${empty user.flag }">value="1"</c:if><c:if test="${not empty user.flag }">value="${user.flag }"</c:if> id="flag"/>
			<input type="checkbox" lay-filter="filter1"  name="switch" lay-skin="switch" lay-text="开启|停用" checked>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">所属部门</label>
			<div class="layui-input-block">
			<select name="deptId" lay-verify="required">
		        <option value=""></option>
		       <c:forEach items="${depts }" var="dept">
		       	<option value="${dept.id }" <c:if test="${user.deptId==dept.id }">selected</c:if>>${dept.deptName }</option>
		       </c:forEach>
		      </select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">所属角色</label>
			<div class="layui-input-block">
			<select name="roleId" lay-verify="required">
		        <option value=""></option>
		       <c:forEach items="${roles }" var="dept">
		       	<option value="${dept.id }" <c:if test="${user.roleId==dept.id }">selected</c:if>>${dept.roleName }</option>
		       </c:forEach>
		      </select>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn userEditBtn" type="button" lay-filter="addNews">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		</div>
	</form>
	<script type="text/javascript" src="layui/layui/layui.js"></script>
<script type="text/javascript">
layui.config({
	base : "js/"
}).use(['form','layer','jquery','laypage'],function(){
	var form = layui.form();
	var $ = layui.jquery;
	$(".userEditBtn").click(function(){
		var data = $("form").serialize();
		$.ajax({
			url:'system/user/save',
			data:data,
			type:'post',
			dataType:'json',
			success:function(ret){
				if(ret.status){
					layui.layer.alert('操作成功!',function(){
					layui.layer.closeAll();
					parent.document.location.href="system/user/data";
					});
				}else{
					layui.layer.msg('操作失败！');
				}
			},
			error:function(ret){
				layui.layer.msg('请确定网络连接');
			}
		});
	});
	form.on('switch(filter1)', function(data){
	var obj = data.elem;
	if(obj.checked){
		$("#flag").val('1');
	}else{
		$("#flag").val('0');
	}
	});  
});
</script>
</body>
</html>